package my.presentation;

import boundary.ItemPedidoFacade;
import boundary.PedidoFacade;
import boundary.PizzaFacade;
import entities.ItemPedido;
import entities.Pizza;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

@ManagedBean(name = "ItemPedidoView")
@RequestScoped
public class ItemPedidoView {

    @EJB
    private ItemPedidoFacade itemPedidoFacade;
    
    @EJB
    private PizzaFacade pizzaFacade;
    
    @EJB
    private PedidoFacade pedidoFacade;
    
    // Creates a new field
    private ItemPedido itemPedido;
    private Long pizzaID;
    private Long pedidoID;

    public Long getPedidoID() {
        return pedidoID;
    }

    public void setPedidoID(Long pedidoID) {
        this.pedidoID = pedidoID;
    }

    public Long getPizzaID() {
        return pizzaID;
    }

    public void setPizzaID(Long pizzaID) {
        this.pizzaID = pizzaID;
    }

    public ItemPedidoView() {
        this.itemPedido = new ItemPedido();
    }

    public ItemPedido getItemPedido() {
        return itemPedido;
    }

    public String postItemPedido() {

        this.itemPedido.setPizza(pizzaFacade.find(pizzaID));
        this.itemPedido.setPedido(pedidoFacade.find(pedidoID));
        
        this.itemPedidoFacade.create(itemPedido);
        return "theend";
    }
    
}
